package com.iursp.validate.code.sms;

import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

import com.iursp.properties.SecurityProperties;
import com.iursp.validate.code.ValidateCodeGenerator;
import com.iursp.validate.code.model.ValidateCode;

/**
 * 
 * @ClassName:  SmsCodeGenerator   
 * @Description:短信验证码生成 
 * @author: ruiwu
 * @date:   2018年6月25日 下午7:10:31   
 *
 */
@Component("smsValidateCodeGenerator")
public class SmsCodeGenerator implements ValidateCodeGenerator {

    @Autowired
    private SecurityProperties securityProperties;

    @Override
    public ValidateCode generate(ServletWebRequest request) {
        String code = RandomStringUtils.randomNumeric(securityProperties.getCode().getSms().getLength());
        return new ValidateCode(code, securityProperties.getCode().getSms().getExpireIn());
    }
}
